package com.kaisheng.dao;

import java.sql.ResultSet;
import java.sql.SQLException;



import com.kaisheng.entity.Idea;
import com.kaisheng.util.DBHelp;

import com.kaisheng.util.RowMapper;



public class IdeaDao {

	private DBHelp<Idea> db = new DBHelp<Idea>();
	
	

	private class IdeaRowMapper implements RowMapper<Idea> {

		public Idea mapRow(ResultSet rs) throws SQLException {
			Idea i = new Idea();
			i.setId(rs.getString("id"));
			i.setTitle(rs.getString("title"));
			i.setContent(rs.getString("content"));
			i.setCreatetime(rs.getString("createtime"));
			i.setUser_id(rs.getString("user_id"));
			i.setProject_id(rs.getString("project_id"));
			
			
			return i;
		}
		
		
		
		
		
	}

	public void saveIdea(Idea i) {
		String sql = "INSERT INTO t_idea (id,title,content,createtime,user_id,project_id) VALUES (?,?,?,?,?,?)";
		db.executeSQL(sql, i.getId(),i.getTitle(),i.getContent(),i.getCreatetime(),i.getUser_id(),i.getProject_id());
	}

	public Idea findIdeaById(String ideaid) {
	
		String sql = "SELECT id,title,content,createtime,user_id,project_id FROM t_idea WHERE id = ?";
		return db.executeQueryForObject(sql,new IdeaRowMapper(), ideaid);
	}

	public void updateIdea(String id,String title,String content,String createtime) {
		String sql = "UPDATE t_idea SET title = ?,content = ?,createtime=? WHERE id = ?";
		db.executeSQL(sql,title,content,createtime,id);
		
		
	}

	public void deleteIdeaById(String id) {
	
		String sql = "DELETE FROM t_idea WHERE id =?";
		db.executeSQL(sql,id);
		
	}

	
	
}
